Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.sun.java.swing.table.TableColumn

java.lang.Object
  |
  +--com.sun.java.swing.table.TableColumn

public class TableColumn
extends java.lang.Object
implements java.io.Serializable
A TableColumn represents all the attributes of a column in a JTable, such as width, resizibility, minimum and maximum width. In addition, the TableColumn also helps to determine how the JTable interprets and displays the value objects from the TableModel in the column. This is done using the cellRenderer of the column. For example, the TableModel can give the table Boolean objects for a column. If the column's cellRenderer is a JCheckBox component then the table will be able to show the Boolean value as a checkbox. If the column's cellEditor is set similarly the user will then be able to modify the cell value using a JCheckBox. This pairing of source's value object with cell renders and editors gives the table a great deal of power and flexibility. Because the table does not need to know anything about the data being displayed, the user is free to customize it.

The TableColumn stores the link between the columns in the JTable and the columns in the TableModel. This, the modelIndex, is the column in the TableModel which will be queried for the data values for the cells in this column. As the column moves around in the view this modelIndex does not change.

It is also possible to specify renderers and editors on a per type basis rather than a per column basis - see the setDefaultRenderer() method in the JTable. This default mechanism is only used when the renderer (or editor) in the TableColumn is null.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
TableColumnModel, DefaultTableColumnModel, Serialized Form

Field Summary
static java.lang.String CELL_RENDERER_PROPERTY
          Bound property name.
TableCellEditor cellEditor
          The editor used to edit the data cells of the column
TableCellRenderer cellRenderer
          The renderer used to draw the data cells of the column
static java.lang.String COLUMN_WIDTH_PROPERTY
          Bound property name.
static java.lang.String HEADER_RENDERER_PROPERTY
          Bound property name.
static java.lang.String HEADER_VALUE_PROPERTY
          Bound property name.
TableCellRenderer headerRenderer
          The renderer used to draw the header of the column
java.lang.Object headerValue
          The header value of the column
java.lang.Object identifier
          This object is not used internally by the drawing machinery of the JTable.
boolean isResizable
          Resizable flag
int maxWidth
          The maximum width of the column
int minWidth
          The minimum width of the column
int modelIndex
          The index of the column in the model which is to be displayed by this TableColumn.
int resizedPostingDisableCount
          Counter used to disable posting of resizing notifications until the end of the resize
int width
          The width of the column
 
Constructor Summary
TableColumn()
          Creates an empty TableColumn.
TableColumn(int modelIndex)
          Creates and initializes an instance of TableColumn with modelIndex.
TableColumn(int modelIndex, int width)
           
TableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor)
           
 
Method Summary
void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
TableCellRenderer createDefaultHeaderRenderer()
           
void disableResizedPosting()
           
void enableResizedPosting()
           
TableCellEditor getCellEditor()
          Returns the TableCellEditor used by the JTable to draw values for this column.
TableCellRenderer getCellRenderer()
          Returns the TableCellRenderer used by the JTable to draw values for this column.
TableCellRenderer getHeaderRenderer()
          Returns the TableCellRenderer used to draw the header of the TableColumn.
java.lang.Object getHeaderValue()
          Returns the Object used as the value for the header renderer.
java.lang.Object getIdentifier()
          Returns the identifier object for this column.
int getMaxWidth()
          Returns the maximum width for the TableColumn.
int getMinWidth()
          Returns the minimum width for the TableColumn.
int getModelIndex()
          Gets the model index for this column.
boolean getResizable()
          Returns true if the user is allowed to resize the TableColumn width, false otherwise.
int getWidth()
          Returns the width of the TableColumn.
void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
void setCellEditor(TableCellEditor anEditor)
          Sets the TableCellEditor used by JTable to draw individual values for this column to anEditor.
void setCellRenderer(TableCellRenderer aRenderer)
          Sets the TableCellRenderer used by JTable to draw individual values for this column to aRenderer.
void setHeaderRenderer(TableCellRenderer aRenderer)
          Sets the TableCellRenderer used to draw the TableColumn's header to aRenderer.
void setHeaderValue(java.lang.Object aValue)
          Sets the Object used as the value for the headerRenderer Posts a bound property change notification with the name HEADER_VALUE_PROPERTY.
void setIdentifier(java.lang.Object anIdentifier)
          Sets the TableColumn's identifier to anIdentifier.
void setMaxWidth(int newMaxWidth)
          Sets the TableColumn's maximum width to newMaxWidth, also adjusting the current width if it's greater than this value.
void setMinWidth(int newMinWidth)
          Sets the TableColumn's minimum width to newMinWidth, also adjusting the current width if it's less than this value.
void setModelIndex(int anIndex)
          Sets the model index for this column.
void setResizable(boolean flag)
          Sets whether the user can resize the receiver in its JTableView.
void setWidth(int newWidth)
          Sets this column's width to newWidth.
void sizeWidthToFit()
          Resizes the TableColumn to fit the width of its header cell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

COLUMN_WIDTH_PROPERTY

public static final java.lang.String COLUMN_WIDTH_PROPERTY
Bound property name.

HEADER_VALUE_PROPERTY

public static final java.lang.String HEADER_VALUE_PROPERTY
Bound property name.

HEADER_RENDERER_PROPERTY

public static final java.lang.String HEADER_RENDERER_PROPERTY
Bound property name.

CELL_RENDERER_PROPERTY

public static final java.lang.String CELL_RENDERER_PROPERTY
Bound property name.

modelIndex

protected int modelIndex
The index of the column in the model which is to be displayed by this TableColumn. As columns are moved around in the view the model index remains constant.

identifier

protected java.lang.Object identifier
This object is not used internally by the drawing machinery of the JTable. Identifiers may be set in the TableColumn as as an optional way to tag and locate TableColumns. The table package does not modify or invoke any methods in these identifer objects other than the equals method which is used in the getColumnIndex() method in the DefaultTableColumnModel.

width

protected int width
The width of the column

minWidth

protected int minWidth
The minimum width of the column

maxWidth

protected int maxWidth
The maximum width of the column

headerRenderer

protected TableCellRenderer headerRenderer
The renderer used to draw the header of the column

headerValue

protected java.lang.Object headerValue
The header value of the column

cellRenderer

protected TableCellRenderer cellRenderer
The renderer used to draw the data cells of the column

cellEditor

protected TableCellEditor cellEditor
The editor used to edit the data cells of the column

isResizable

protected boolean isResizable
Resizable flag

resizedPostingDisableCount

protected transient int resizedPostingDisableCount
Counter used to disable posting of resizing notifications until the end of the resize
Constructor Detail

TableColumn

public TableColumn()
Creates an empty TableColumn. This is intended for the use of the serialization code.


TableColumn

public TableColumn(int modelIndex)
Creates and initializes an instance of TableColumn with modelIndex. The modelIndex is the index of the column in the model which will supply the data for this column in the table. This, like the columnIdentifier in previous releases, does not change as the columns are moved in the view.

Parameters:
modelIndex - the column in the model which provides the values for this column
See Also:
#setHeaderValue()

TableColumn

public TableColumn(int modelIndex,
                   int width)

TableColumn

public TableColumn(int modelIndex,
                   int width,
                   TableCellRenderer cellRenderer,
                   TableCellEditor cellEditor)
Method Detail

setModelIndex

public void setModelIndex(int anIndex)
Sets the model index for this column. The model index is the index of the column in the model that will be displayed by this TableColumn. As the TableColumn is moved around in the view the model index remains constant.

getModelIndex

public int getModelIndex()
Gets the model index for this column.

setIdentifier

public void setIdentifier(java.lang.Object anIdentifier)
Sets the TableColumn's identifier to anIdentifier. Note identifiers are not used by the JTable, they are purely a convenience for the external tagging and location of columns.
Parameters:
anIdentifier - an identifier for this column
See Also:
getIdentifier()

getIdentifier

public java.lang.Object getIdentifier()
Returns the identifier object for this column. Note identifiers are not used by the JTable, they are purely a convenience for external use. If the identifier is null getIdentifier() returns getHeaderValue() as a default.
Returns:
the idenitifer object for this column
See Also:
#setIdentifier()

setHeaderRenderer

public void setHeaderRenderer(TableCellRenderer aRenderer)
Sets the TableCellRenderer used to draw the TableColumn's header to aRenderer. Posts a bound property change notification with the name HEADER_RENDERER_PROPERTY.
Parameters:
aRenderer - the new header renderer
Throws:
java.lang.IllegalArgumentException - if aRenderer is null.
See Also:
getHeaderRenderer()

getHeaderRenderer

public TableCellRenderer getHeaderRenderer()
Returns the TableCellRenderer used to draw the header of the TableColumn. The default header renderer is a JCellRenderer initialized with a JLabel.
Returns:
the TableCellRenderer used to draw the header
See Also:
#setHeaderRenderer(), #setHeaderValue()

setHeaderValue

public void setHeaderValue(java.lang.Object aValue)
Sets the Object used as the value for the headerRenderer Posts a bound property change notification with the name HEADER_VALUE_PROPERTY.
Parameters:
aValue - the new header value
See Also:
getHeaderValue()

getHeaderValue

public java.lang.Object getHeaderValue()
Returns the Object used as the value for the header renderer.
Returns:
the Object used as the value for the header renderer
See Also:
#setHeaderValue()

setCellRenderer

public void setCellRenderer(TableCellRenderer aRenderer)
Sets the TableCellRenderer used by JTable to draw individual values for this column to aRenderer. Posts a bound property change notification with the name CELL_RENDERER_PROPERTY.
Parameters:
aRenderer - the new data cell renderer
See Also:
getCellRenderer()

getCellRenderer

public TableCellRenderer getCellRenderer()
Returns the TableCellRenderer used by the JTable to draw values for this column. The cellRenderer of the column not only controls the visual look for the column, but is also used to interpret the value object supplied by the TableModel. The default cellRenderer is a JCellRenderer initialized with a JLabel.
Returns:
the TableCellRenderer used by the JTable to draw values for this column
See Also:
#setCellRenderer()

setCellEditor

public void setCellEditor(TableCellEditor anEditor)
Sets the TableCellEditor used by JTable to draw individual values for this column to anEditor. A null editor means the column is not editable.
Parameters:
anEditor - the new data cell editor
See Also:
getCellEditor()

getCellEditor

public TableCellEditor getCellEditor()
Returns the TableCellEditor used by the JTable to draw values for this column. The cellEditor of the column not only controls the visual look for the column, but is also used to interpret the value object supplied by the TableModel. The default cellEditor is null.
Returns:
the TableCellEditor used by the JTable to draw values for this column
See Also:
#setCellEditor()

setWidth

public void setWidth(int newWidth)
Sets this column's width to newWidth. If newWidth exceeds the minimum or maximum width, it's adjusted to the appropriate limiting value. Posts a bound property change notification with the name COLUMN_WIDTH_PROPERTY.

Note: The default resize mode of the JTable is AUTO_RESIZE_ALL_COLUMNS, which causes the JTable to control the widths of the columns itself and so override any widths set by an application using this method. To control the widths of the columns progammatically, be sure to first call setAutoResizeMode(AUTO_RESIZE_OFF) on the JTable.

Parameters:
newWidth - The new width value
See Also:
getWidth(), getMinWidth(), #setMinWidth(), getMaxWidth(), #setMaxWidth()

getWidth

public int getWidth()
Returns the width of the TableColumn. The default width is 75.
Returns:
the width of the TableColumn
See Also:
#setWidth(), getMinWidth(), #setMinWidth(), getMaxWidth(), #setMaxWidth()

setMinWidth

public void setMinWidth(int newMinWidth)
Sets the TableColumn's minimum width to newMinWidth, also adjusting the current width if it's less than this value.
Parameters:
newMinWidth - the new minimum width value
See Also:
getWidth(), #setWidth(), getMinWidth(), getMaxWidth(), #setMaxWidth()

getMinWidth

public int getMinWidth()
Returns the minimum width for the TableColumn. The TableColumn's width can't be made less than this either by the user or programmatically. The default minWidth is 15.
Returns:
the minimum width for the TableColumn
See Also:
getWidth(), #setWidth(), #setMinWidth(), getMaxWidth(), #setMaxWidth()

setMaxWidth

public void setMaxWidth(int newMaxWidth)
Sets the TableColumn's maximum width to newMaxWidth, also adjusting the current width if it's greater than this value.
Parameters:
newMaxWidth - the new maximum width value
See Also:
getWidth(), #setWidth(), getMinWidth(), #setMinWidth(), getMaxWidth()

getMaxWidth

public int getMaxWidth()
Returns the maximum width for the TableColumn. The TableColumn's width can't be made larger than this either by the user or programmatically. The default maxWidth is 2000.
Returns:
the maximum width for the TableColumn.
See Also:
getWidth(), #setWidth(), getMinWidth(), #setMinWidth(), #setMaxWidth()

setResizable

public void setResizable(boolean flag)
Sets whether the user can resize the receiver in its JTableView.
Parameters:
flag - true if the column isResizable
See Also:
getResizable()

getResizable

public boolean getResizable()
Returns true if the user is allowed to resize the TableColumn width, false otherwise. You can change the width programmatically regardless of this setting. The default is true.
Returns:
true if the user is allowed to resize the TableColumn width, false otherwise.
See Also:
#setResizable()

sizeWidthToFit

public void sizeWidthToFit()
Resizes the TableColumn to fit the width of its header cell. If the maximum width is less than the width of the header, the maximum is increased to the header's width. Similarly, if the minimum width is greater than the width of the header, the minimum is reduced to the header's width.
See Also:
#setWidth(), #setMinWidth(), #setMaxWidth()

disableResizedPosting

public void disableResizedPosting()

enableResizedPosting

public void enableResizedPosting()

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to an explicit setFont, setBackground, or SetForeground on the current component. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

Parameters:
listener - The PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.
Parameters:
listener - The PropertyChangeListener to be removed

createDefaultHeaderRenderer

protected TableCellRenderer createDefaultHeaderRenderer()

Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Submit a bug or feature
Submit comments/suggestions about javadoc
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.